package com.estronger.shopmanage.ui.order.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.View;

import com.estronger.shopmanage.fragment.ImageFragment;
import java.util.List;


/**
 * Created by Administrator on 2017-04-01.
 */

public class ImageViewPagerAdapter extends FragmentStatePagerAdapter {
    List<String> mDatas;
    private View.OnClickListener imgListener;
    private View.OnLongClickListener longClickListener;

    public ImageViewPagerAdapter(FragmentManager fm, List<String> data, View.OnLongClickListener longClickListener) {
        super(fm);
        mDatas = data;
        this.imgListener = null;
        this.longClickListener = longClickListener;
    }
    public ImageViewPagerAdapter(FragmentManager fm, List<String> data, View.OnClickListener imgListener, View.OnLongClickListener longClickListener) {
        super(fm);
        mDatas = data;
        this.imgListener = imgListener;
        this.longClickListener = longClickListener;
    }

    @Override
    public Fragment getItem(int position) {
        String url = mDatas.get(position);
        ImageFragment fragment = ImageFragment.newInstance(url);
        if(url==null || url.equals("") || !url.trim().startsWith("http")){
            fragment.setImgListener(imgListener, null);
        }else {
            fragment.setImgListener(imgListener, longClickListener);
        }
        return fragment;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

}
